﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Frame.Lib.Utilities;
using Frame.Lib.Common;
using Frame.Lib.Web;
using Frame.Lib.Core.Para;

namespace Frame.Web.Admin.Para
{
    public partial class List : PageList
    {
        private ParaBO Paras
        {
            get
            {
                return ParaBO.Instance<ParaBO>();
            }
        }
        //private PagerSortSetting _setting;
        protected void Page_Load(object sender, EventArgs e)
        {
            // _setting = Footer1.InitPager(new BindViewHandler(BindView));
            if (!IsPostBack)
            {
                BindView();
            }
            AddAttr();
            base.InitSelectID(hidSelectIDs);
            JSUtil.SetTableHeight("list", 160);
        }

        private void AddAttr()
        {
            JSUtil.DelConfirm(btnDelete, "参数");
            JSUtil.ShowForm(lnkAdd, "增加参数", null, GlobalVar.WebCurrPath + "Edit.aspx", 380, 244);
            JSUtil.ClickBtn(lnkDelete, btnDelete);
        }

        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            chkSelectAll.Checked = false;

            PagerSetting setting = new PagerSetting();
            setting.PageIndex = this.PageIndex;
            setting.PageSize = AppSetting.PageSize;
            setting.OrderBy = "Orders";
           

            IEnumerable<ParaInfo> list = Paras.GetList(setting);
            lv.DataSource = list;
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataBind();

            string prefix = GlobalVar.WebCurrPath + "List.aspx";
            litPager.Text = HtmlPager.Render(setting, prefix, true);

        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs == "")
            {
                return;
            }
            List<string> ids = StrUtil.SplitToStr(strSelectIDs);
            Paras.Delete(ids);
            BindView();
        }

      

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                LVUtil.SetEdit(sender, e, 380, 244);
                
            }
        }
    }
}